﻿<template>
	<div class="card-fill layout-padding" v-loading="loading || ocrLoading" element-loading-text="Loading...">
		<el-tabs v-model="activeTab">
			<el-tab-pane label="基本信息" name="main">
				<el-card shadow="hover" class="layout-padding-auto create-form">
					<el-form ref="formRef" :model="stateData.vmModel" label-width="120px">
						<div class="form-section">
							<div class="section-title">
								<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
								<span>应聘信息</span>
							</div>

							<el-row :gutter="24">
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_RecruitPublishId_FormItem"
										prop="Entity.RecruitPublishRequestBillId"
										:rules="[{ required: true, message: '请选择招聘发布单', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="招聘发布单" tooltip="选择招聘发布单" />
										</template>
										<el-select
											v-model="stateData.vmModel.Entity.RecruitPublishRequestBillId"
											clearable
											filterable
											remote
											:remote-method="searchRecruitPublish"
											:loading="recruitPublishLoading"
											placeholder="请输入招聘发布单号查询"
											class="width100"
										>
											<el-option
												v-for="item in recruitPublishOptions"
												:key="item.ID"
												:value="item.ID"
												:label="`${item.BillCode} - ${item.Title}`"
											></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<!-- <el-col :xs="24" :sm="12" class="mb20">
					<el-form-item
						ref="Entity_ArrivalDate_FormItem"
						prop="Entity.ArrivalDate"
						:rules="[{ required: true, message: '可到岗时间为必填项', trigger: 'blur' }]"
					>
						<template #label>
							<WtmLabelTooltip label="可到岗时间" tooltip="可到岗时间" />
						</template>
						<el-date-picker v-model="stateData.vmModel.Entity.ArrivalDate" clearable class="width100"></el-date-picker>
					</el-form-item>
				</el-col> -->
								<!-- <el-col :xs="24" :sm="12" class="mb20">
					<el-form-item ref="Entity_WorkExperience_FormItem" prop="Entity.WorkExperience">
						<template #label>
							<WtmLabelTooltip label="工作年限(年)" tooltip="工作年限(年)" />
						</template>
						<el-input-number
							v-model="stateData.vmModel.Entity.WorkExperience"
							:min="0"
							:precision="1"
							clearable
							class="width100"
						></el-input-number>
					</el-form-item>
				</el-col> -->
								<el-col :xs="24" :lg="12" class="mb20">
									<el-form-item ref="Entity_CurrentSalary_FormItem" prop="Entity.CurrentSalary">
										<template #label>
											<WtmLabelTooltip label="原薪酬" tooltip="原薪酬" />
										</template>
										<el-input-number v-model="stateData.vmModel.Entity.CurrentSalary" clearable class="width100"></el-input-number>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item ref="Entity_ExpectedSalary_FormItem" prop="Entity.ExpectedSalary">
										<template #label>
											<WtmLabelTooltip label="期望薪酬" tooltip="期望薪酬" />
										</template>
										<el-input-number v-model="stateData.vmModel.Entity.ExpectedSalary" clearable class="width100"></el-input-number>
									</el-form-item>
								</el-col>
							</el-row>
						</div>

						<div class="form-section">
							<div class="section-title">
								<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
								<span>单据信息</span>
							</div>

							<el-row :gutter="24">
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item ref="Entity_BillCode_FormItem" prop="Entity.BillCode">
										<template #label>
											<WtmLabelTooltip label="单据编号" tooltip="单据编号" />
										</template>
										<el-input v-model="stateData.vmModel.Entity.BillCode" clearable class="width100" disabled></el-input>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item ref="Entity_Remark_FormItem" prop="Entity.Remark">
										<template #label>
											<WtmLabelTooltip label="备注" tooltip="备注" />
										</template>
										<el-input v-model="stateData.vmModel.Entity.Remark" clearable class="width100" type="textarea" :rows="2"></el-input>
									</el-form-item>
								</el-col>
							</el-row>
						</div>

						<div class="form-section">
							<div class="section-title">
								<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
								<span>基本信息</span>
							</div>

							<el-row :gutter="24">
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item ref="Entity_Name_FormItem" prop="Entity.Name" :rules="[{ required: true, message: '姓名为必填项', trigger: 'blur' }]">
										<template #label>
											<WtmLabelTooltip label="姓名" tooltip="应聘者姓名" />
										</template>
										<el-input v-model="stateData.vmModel.Entity.Name" clearable class="width100"></el-input>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_Gender_FormItem"
										prop="Entity.Gender"
										:rules="[{ required: true, message: '性别为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="性别" tooltip="性别" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.Gender" clearable class="width100" disabled>
											<el-option key="男" value="男" label="男"></el-option>
											<el-option key="女" value="女" label="女"></el-option>
											<el-option key="其他" value="其他" label="其他"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_BirthDate_FormItem"
										prop="Entity.BirthDate"
										:rules="[{ required: true, message: '出生日期为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="出生日期" tooltip="出生日期" />
										</template>
										<el-date-picker v-model="stateData.vmModel.Entity.BirthDate" clearable class="width100" disabled></el-date-picker>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item ref="Entity_Ethnicity_FormItem" prop="Entity.Ethnicity">
										<template #label>
											<WtmLabelTooltip label="民族" tooltip="民族" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.Ethnicity" clearable class="width100" disabled>
											<el-option key="汉族" value="汉族" label="汉族"></el-option>
											<el-option key="回族" value="回族" label="回族"></el-option>
											<el-option key="满族" value="满族" label="满族"></el-option>
											<el-option key="蒙古族" value="蒙古族" label="蒙古族"></el-option>
											<el-option key="壮族" value="壮族" label="壮族"></el-option>
											<el-option key="其他" value="其他" label="其他"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<!-- 身体信息字段 -->
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_Height_FormItem"
										prop="Entity.Height"
										:rules="[{ required: true, message: '身高为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="身高(cm)" tooltip="身高（厘米）" />
										</template>
										<el-input-number
											v-model="stateData.vmModel.Entity.Height"
											:min="0"
											:max="250"
											:precision="1"
											clearable
											class="width100"
										></el-input-number>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_Weight_FormItem"
										prop="Entity.Weight"
										:rules="[{ required: true, message: '体重为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="体重(kg)" tooltip="体重（公斤）" />
										</template>
										<div style="display: flex; align-items: center; gap: 10px">
											<el-input-number
												v-model="stateData.vmModel.Entity.Weight"
												:min="0"
												:max="150"
												:precision="1"
												clearable
												style="flex: 1"
											></el-input-number>
											<span v-if="stateData.vmModel.Entity.Weight" style="white-space: nowrap; color: #606266">
												≈ {{ (stateData.vmModel.Entity.Weight * 2).toFixed(1) }} 斤
											</span>
										</div>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item ref="Entity_HighestEducation_FormItem" prop="Entity.HighestEducation" :rules="[{ required: true, message: '最高学历为必填项', trigger: 'blur' }]">
										<template #label>
											<WtmLabelTooltip label="最高学历" tooltip="最高学历" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.HighestEducation" clearable class="width100">
											<el-option key="小学" value="小学" label="小学"></el-option>
											<el-option key="初中" value="初中" label="初中"></el-option>
											<el-option key="高中" value="高中" label="高中"></el-option>
											<el-option key="中专" value="中专" label="中专"></el-option>
											<el-option key="大专" value="大专" label="大专"></el-option>
											<el-option key="本科" value="本科" label="本科"></el-option>
											<el-option key="研究生" value="研究生" label="研究生"></el-option>
											<el-option key="硕士" value="硕士" label="硕士"></el-option>
											<el-option key="博士" value="博士" label="博士"></el-option>
											<el-option key="博士后" value="博士后" label="博士后"></el-option>
											<el-option key="博士研究生" value="博士研究生" label="博士研究生"></el-option>
											<el-option key="其他" value="其他" label="其他"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_MajorCategory_FormItem"
										prop="Entity.MajorCategory"
										:rules="[{ required: true, message: '专业大类为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="专业大类" tooltip="专业大类" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.MajorCategory" clearable class="width100">
											<el-option key='化学化工类' value='化学化工类' label="化学化工类"></el-option>
											<el-option key="工学" value="工学" label="工学"></el-option>
											<el-option key="理学" value="理学" label="理学"></el-option>
											<el-option key="医学" value="医学" label="医学"></el-option>
											<el-option key="农学" value="农学" label="农学"></el-option>
											<el-option key="管理学" value="管理学" label="管理学"></el-option>
											<el-option key="经济学" value="经济学" label="经济学"></el-option>
											<el-option key="法学" value="法学" label="法学"></el-option>
											<el-option key="文学" value="文学" label="文学"></el-option>
											<el-option key="教育学" value="教育学" label="教育学"></el-option>
											<el-option key="艺术学" value="艺术学" label="艺术学"></el-option>
											<el-option key="历史学" value="历史学" label="历史学"></el-option>
											<el-option key="哲学" value="哲学" label="哲学"></el-option>
											<el-option key="其他" value="其他" label="其他"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_MajorName_FormItem"
										prop="Entity.MajorName"
										:rules="[{ required: true, message: '专业名称为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="专业名称" tooltip="专业名称" />
										</template>
										<el-input v-model="stateData.vmModel.Entity.MajorName" clearable class="width100"></el-input>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item ref="Entity_MaritalStatus_FormItem" prop="Entity.MaritalStatus" :rules="[{ required: true, message: '婚姻状况为必填项', trigger: 'blur' }]">
										<template #label>
											<WtmLabelTooltip label="婚姻状况" tooltip="婚姻状况" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.MaritalStatus" clearable class="width100">
											<el-option key="未婚" value="未婚" label="未婚"></el-option>
											<el-option key="已婚" value="已婚" label="已婚"></el-option>
											<el-option key="离异" value="离异" label="离异"></el-option>
											<el-option key="丧偶" value="丧偶" label="丧偶"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_FertilityStatus_FormItem"
										prop="Entity.FertilityStatus"
										:rules="[{ required: true, message: '生育状况为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="生育状况" tooltip="生育状况" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.FertilityStatus" clearable class="width100">
											<el-option key="未育" value="未育" label="未育"></el-option>
											<el-option key="一育" value="一育" label="一育"></el-option>
											<el-option key="二育" value="二育" label="二育"></el-option>
											<el-option key="三育" value="三育" label="三育"></el-option>
											<el-option key="四育及以上" value="四育及以上" label="四育及以上"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_PhotoId_FormItem"
										prop="Entity.PhotoId"
										:rules="[{ required: true, message: '照片为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="照片" tooltip="请上传个人近身照" />
										</template>
										<wtm-upload-image v-model="stateData.vmModel.Entity.PhotoId" clearable class="width100"></wtm-upload-image>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_IsLaborRelationshipTerminated_FormItem"
										prop="Entity.IsLaborRelationshipTerminated"
										:rules="[{ required: true, message: '请选择是否解除劳动合同', trigger: 'change' }]"
									>
										<template #label>
											<WtmLabelTooltip label="是否解除劳动合同" tooltip="上家单位劳动关系是否已解除" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.IsLaborRelationshipTerminated" clearable class="width100">
											<el-option key="是" :value="true" label="是"></el-option>
											<el-option key="否" :value="false" label="否"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_IsVeteran_FormItem"
										prop="Entity.IsVeteran"
										:rules="[{ required: true, message: '请选择是否退伍军人', trigger: 'change' }]"
									>
										<template #label>
											<WtmLabelTooltip label="是否退伍军人" tooltip="是否为退伍军人" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.IsVeteran" clearable class="width100">
											<el-option key="是" :value="true" label="是"></el-option>
											<el-option key="否" :value="false" label="否"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col v-if="stateData.vmModel.Entity.IsVeteran === true" :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_VeteranCertificateId_FormItem"
										prop="Entity.VeteranCertificateId"
										:rules="[{ required: stateData.vmModel.Entity.IsVeteran === true, message: '请上传退伍证图片', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="退伍证图片" tooltip="退伍证图片" />
										</template>
										<wtm-upload-image v-model="stateData.vmModel.Entity.VeteranCertificateId" clearable class="width100"></wtm-upload-image>
									</el-form-item>
								</el-col>
								<!-- 亲属关系相关字段 -->
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_HasRelativeInCompany_FormItem"
										prop="Entity.HasRelativeInCompany"
										:rules="[{ required: true, message: '亲属关系为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="亲属关系" tooltip="是否与本单位职工存在亲属关系" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.HasRelativeInCompany" clearable class="width100">
											<el-option key="是" :value="true" label="是"></el-option>
											<el-option key="否" :value="false" label="否"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col v-if="stateData.vmModel.Entity.HasRelativeInCompany === true" :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_RelationshipType_FormItem"
										prop="Entity.RelationshipType"
										:rules="[{ required: stateData.vmModel.Entity.HasRelativeInCompany === true, message: '请选择亲属关系类型', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="亲属关系" tooltip="与公司内员工的亲属关系类型" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.RelationshipType" clearable class="width100">
											<el-option key="父亲" value="父亲" label="父亲"></el-option>
											<el-option key="母亲" value="母亲" label="母亲"></el-option>
											<el-option key="配偶" value="配偶" label="配偶"></el-option>
											<el-option key="子女" value="子女" label="子女"></el-option>
											<el-option key="兄弟姐妹" value="兄弟姐妹" label="兄弟姐妹"></el-option>
											<el-option key="其他" value="其他" label="其他"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col v-if="stateData.vmModel.Entity.HasRelativeInCompany === true" :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_RelativeName_FormItem"
										prop="Entity.RelativeName"
										:rules="[{ required: stateData.vmModel.Entity.HasRelativeInCompany === true, message: '请输入亲属姓名', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="亲属姓名" tooltip="公司内亲属的姓名" />
										</template>
										<el-input v-model="stateData.vmModel.Entity.RelativeName" clearable class="width100"></el-input>
									</el-form-item>
								</el-col>
							</el-row>
						</div>

						<div class="form-section">
							<div class="section-title">
								<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
								<span>身份信息</span>
							</div>

							<el-row :gutter="24">
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_IdCardNo_FormItem"
										prop="Entity.IdCardNo"
										:rules="[{ required: true, message: '身份证号为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="身份证号" tooltip="身份证号码" />
										</template>
										<el-input
											v-model="stateData.vmModel.Entity.IdCardNo"
											@blur="parseIdCardInfo"
											clearable
											class="width100"
											disabled
											placeholder="请上传身份证正反面照片"
										></el-input>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item ref="Entity_IdCardExpiryDate_FormItem" prop="Entity.IdCardExpiryDate">
										<template #label>
											<WtmLabelTooltip label="身份证有效期" tooltip="身份证有效期" />
										</template>
										<el-input
											:value="other.formatIdCardExpiry(stateData.vmModel.Entity.IdCardExpiryDate)"
											clearable
											class="width100"
											disabled
											placeholder="上传身份证国徽面后自动填充"
										></el-input>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_IdCardFrontPhotoId_FormItem"
										prop="Entity.IdCardFrontPhotoId"
										:rules="[{ required: true, message: '身份证人像面为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="身份证人像面" tooltip="身份证人像面文件" />
										</template>
										<wtm-upload-image
											v-model="stateData.vmModel.Entity.IdCardFrontPhotoId"
											clearable
											class="width100"
											@update:model-value="handleUploadRefresh($event, 'front')"
										></wtm-upload-image>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_IdCardBackPhotoId_FormItem"
										prop="Entity.IdCardBackPhotoId"
										:rules="[{ required: true, message: '身份证国徽面为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="身份证国徽面" tooltip="身份证国徽面文件" />
										</template>
										<wtm-upload-image
											v-model="stateData.vmModel.Entity.IdCardBackPhotoId"
											clearable
											class="width100"
											@update:model-value="handleUploadRefresh($event, 'back')"
										></wtm-upload-image>
									</el-form-item>
								</el-col>
							</el-row>
						</div>

						<div class="form-section">
							<div class="section-title">
								<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
								<span>户籍信息</span>
							</div>

							<el-row :gutter="24">
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item ref="Entity_HouseholdRegistration_FormItem" prop="Entity.HouseholdRegistration">
										<template #label>
											<WtmLabelTooltip label="户口所在地" tooltip="户口所在地" />
										</template>
										<el-input v-model="stateData.vmModel.Entity.HouseholdRegistration" clearable class="width100" disabled />
									</el-form-item>
								</el-col>
								<!-- <el-col :xs="24" :sm="12" class="mb20">
						<el-form-item ref="Entity_NativePlace_FormItem" prop="Entity.NativePlace">
							<template #label>
								<WtmLabelTooltip label="籍贯" tooltip="籍贯" />
							</template>
							<el-input v-model="stateData.vmModel.Entity.NativePlace" clearable class="width100" disabled />
						</el-form-item>
					</el-col> -->
							</el-row>
						</div>

						<div class="form-section">
							<div class="section-title">
								<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
								<span>政治面貌</span>
							</div>

							<el-row :gutter="24">
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item ref="Entity_PoliticalStatus_FormItem" prop="Entity.PoliticalStatus">
										<template #label>
											<WtmLabelTooltip label="政治面貌" tooltip="政治面貌" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.PoliticalStatus" clearable class="width100">
											<el-option key="共青团员" value="共青团员" label="共青团员"></el-option>
											<el-option key="中共党员" value="中共党员" label="中共党员"></el-option>
											<el-option key="群众" value="群众" label="群众"></el-option>
											<el-option key="无党派人士" value="无党派人士" label="无党派人士"></el-option>
											<el-option key="其他" value="其他" label="其他"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<!-- <el-col :xs="24" :lg="12" class="mb20">
					<el-form-item ref="Entity_PartyJoinDate_FormItem" prop="Entity.PartyJoinDate">
						<template #label>
							<WtmLabelTooltip label="入党(团)日期" tooltip="入党或入团日期" />
						</template>
						<el-date-picker v-model="stateData.vmModel.Entity.PartyJoinDate" clearable class="width100"></el-date-picker>
					</el-form-item>
				</el-col> -->
								<!-- <el-col :xs="24" :lg="12" class="mb20">
					<el-form-item ref="Entity_PartyBranch_FormItem" prop="Entity.PartyBranch">
						<template #label>
							<WtmLabelTooltip label="入党所在支部" tooltip="入党所在支部" />
						</template>
						<el-input v-model="stateData.vmModel.Entity.PartyBranch" clearable class="width100"></el-input>
					</el-form-item>
				</el-col> -->
							</el-row>
						</div>

						<div class="form-section">
							<div class="section-title">
								<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
								<span>联系方式</span>
							</div>

							<el-row :gutter="24">
								<el-col :xs="24" :sm="12" class="mb20">
									<el-form-item
										ref="Entity_Phone_FormItem"
										prop="Entity.Phone"
										:rules="[
											{ required: true, message: '手机号为必填项', trigger: 'blur' },
											{ validator: validatePhone, trigger: 'blur' },
										]"
									>
										<template #label>
											<WtmLabelTooltip label="手机号" tooltip="手机号码" />
										</template>
										<el-input v-model="stateData.vmModel.Entity.Phone" clearable class="width100"></el-input>
									</el-form-item>
								</el-col>
								<!-- <el-col :xs="24" :sm="12" class="mb20">
					<el-form-item ref="Entity_Email_FormItem" prop="Entity.Email">
						<template #label>
							<WtmLabelTooltip label="邮箱" tooltip="电子邮箱" />
						</template>
						<el-input v-model="stateData.vmModel.Entity.Email" clearable class="width100"></el-input>
					</el-form-item>
				</el-col> -->
								<el-col :xs="24" class="mb20">
									<el-form-item ref="Entity_HomeAddress_FormItem" prop="Entity.HomeAddress">
										<template #label>
											<WtmLabelTooltip label="现住址" tooltip="现在所居住的地址" />
										</template>
										<el-input v-model="stateData.vmModel.Entity.HomeAddress" clearable class="width100"></el-input>
									</el-form-item>
								</el-col>
							</el-row>
						</div>

						<div class="form-section">
							<div class="section-title">
								<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
								<span>工作信息</span>
							</div>

							<el-row :gutter="24">
								<!-- <el-col :xs="24" :lg="12" class="mb20">
									<el-form-item
										ref="Entity_OrgId_FormItem"
										prop="Entity.OrgId"
										:rules="[{ required: true, message: '公司为必填项', trigger: 'blur' }]"
									>
										<template #label>
											<WtmLabelTooltip label="公司" tooltip="关联的公司" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.OrgId" clearable class="width100">
											<el-option v-for="item in stateData.AllSysOrgs" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :lg="24" class="mb20">
									<WtmDeptSelector
										v-model:model-value="stateData.vmModel.Entity.GroupId"
										v-model:position-id="stateData.vmModel.Entity.JobPositionId"
										prop="Entity.GroupId"
										position-prop="Entity.JobPositionId"
										label="所属部门"
										position-label="工作岗位"
										:rules="[]"
										:position-rules="[]"
										:show-position="true"
										:use-row="true"
										:dept-col="12"
										:position-col="12"
									/>
								</el-col> -->
								<el-col :xs="24" :lg="12" class="mb20">
									<el-form-item ref="Entity_JoinWorkDate_FormItem" prop="Entity.JoinWorkDate">
										<template #label>
											<WtmLabelTooltip label="参加工作日期" tooltip="首次参加工作日期" />
										</template>
										<el-date-picker v-model="stateData.vmModel.Entity.JoinWorkDate" clearable class="width100"></el-date-picker>
									</el-form-item>
								</el-col>
								<!-- <el-col :xs="24" :lg="12" class="mb20">
									<el-form-item ref="Entity_EmploymentType_FormItem" prop="Entity.EmploymentType">
										<template #label>
											<WtmLabelTooltip label="用工形式" tooltip="用工形式" />
										</template>
										<el-select v-model="stateData.vmModel.Entity.EmploymentType" clearable class="width100">
											<el-option key="全职" value="全职" label="全职"></el-option>
											<el-option key="兼职" value="兼职" label="兼职"></el-option>
											<el-option key="实习" value="实习" label="实习"></el-option>
											<el-option key="外包" value="外包" label="外包"></el-option>
										</el-select>
									</el-form-item>
								</el-col> -->
							</el-row>
						</div>

						<el-row :gutter="20"></el-row>
					</el-form>
				</el-card>
			</el-tab-pane>
			<el-tab-pane label="学习经历" name="personeducations" v-if="stateData.vmModel.Entity.ID">
				<SysPersonEducation :search-bar="false" :toolbar="true" :is-disabled="true" :person-id="stateData.vmModel.Entity.ID" />
			</el-tab-pane>

			<el-tab-pane label="家庭成员" name="personfamilies" v-if="stateData.vmModel.Entity.ID">
				<SysPersonFamily :search-bar="false" :toolbar="true" :is-disabled="true" :person-id="stateData.vmModel.Entity.ID" />
			</el-tab-pane>

			<el-tab-pane label="工作经历" name="personworks" v-if="stateData.vmModel.Entity.ID">
				<SysPersonWork :search-bar="false" :toolbar="true" :is-disabled="true" :person-id="stateData.vmModel.Entity.ID" />
			</el-tab-pane>

			<!-- <el-tab-pane label="员工履历" name="personresumes" v-if="stateData.vmModel.Entity.ID">
				<SysPersonResume :search-bar="false" :toolbar="true" :is-disabled="true" :person-id="stateData.vmModel.Entity.ID" />
			</el-tab-pane> -->
			<el-tab-pane label="荣誉职称" name="personprofessionaltitles" v-if="stateData.vmModel.Entity.ID">
				<SysPersonProfessionalTitle :search-bar="false" :toolbar="true" :is-disabled="true" :person-id="stateData.vmModel.Entity.ID" />
			</el-tab-pane>
		</el-tabs>
	</div>
</template>

<script setup lang="ts" name="message._system.common.vm.add;false">
import ElMessage from 'element-plus/es/components/message/index';
import {
	reactive,
	ref,
	getCurrentInstance,
	onMounted,
	onUnmounted,
	computed,
	nextTick,
	type ComponentInternalInstance,
	watch,
	defineAsyncComponent,
} from 'vue';
import { SysHrInterviewRequestBillApi as api } from '/@/views/hr/syshrinterviewrequestbill/api';
import other from '/@/utils/other';
import { ISysHrInterviewRequestBillVm } from '/@/views/hr/syshrinterviewrequestbill/api/interface';
import { IViewModel } from '/@/types/common';
import { useIdCardParser } from '/@/hooks/useCardParser';
import { useIdCardOcr } from '/@/hooks/useIdCardOcr';
import { commonApi } from '/@/api/common';
import { SysHrRecruitPublishRequestBillApi } from '/@/views/hr/syshrrecruitpublishrequestbill/api';

// 懒加载子组件
const SysPersonEducation = defineAsyncComponent(() => import('/@/views/person/syspersoneducation/index.vue'));
const SysPersonFamily = defineAsyncComponent(() => import('/@/views/person/syspersonfamily/index.vue'));
const SysPersonWork = defineAsyncComponent(() => import('/@/views/person/syspersonwork/index.vue'));
const SysPersonTrainExam = defineAsyncComponent(() => import('/@/views/person/syspersontrainexam/index.vue'));
const SysPersonMedical = defineAsyncComponent(() => import('/@/views/person/syspersonmedical/index.vue'));
const SysPersonResume = defineAsyncComponent(() => import('/@/views/person/syspersonresume/index.vue'));
const SysPersonContract = defineAsyncComponent(() => import('/@/views/person/syspersoncontract/index.vue'));
const SysPersonProfessionalTitle = defineAsyncComponent(() => import('/@/views/person/syspersonprofessionaltitle/index.vue'));

// 常量定义
const BILL_STATUS = {
	DRAFT: '草稿',
	FORMAL: '正文',
	SUBMITTING: '提交中',
} as const;

const WORKFLOW_STATUS = {
	PENDING: '待提交',
	SUBMITTING: '提交中',
	IN_AUDIT: '审核中',
	APPROVED: '已完成',
	CANCELLED: '已取消',
} as const;

const BUTTON_TEXTS = {
	SAVE: '保存',
	SUBMIT: '提交',
	CLOSE: '关闭',
} as const;

const API_ENDPOINTS = {
	BILL_CODE: '/api/SysHrInterviewRequestBill/GetBillCode',
} as const;

const ci = getCurrentInstance() as ComponentInternalInstance;
const loading = ref(false);
const formRef = ref();
const hasSavedOnce = ref(false);
// 移除招聘需求单号相关代码

// 初始化身份证OCR hooks
const {
	recognizeIdCard,
	loading: ocrLoading, // 新增：解构出 OCR loading
} = useIdCardOcr({
	autoFill: true,
	showMessage: true,
});

// 使用通用的手机号验证方法
const validatePhone = other.validatePhone;

const stateData = reactive<IViewModel<ISysHrInterviewRequestBillVm>>({
	vmModel: {
		Entity: {
			RecruitPublishRequestBillId: null,
			ArrivalDate: null,
			CurrentSalary: null,
			ExpectedSalary: null,
			WorkExperience: null,
			InitialTestTime: null,
			InitialResult: null,
			InitialComment: null,
			ReExamTime: null,
			ReExamResult: null,
			ReExamComment: null,
			FinalResult: null,
			FinalRemark: null,
			RejectReason: null,
			// 单据信息
			BillCode: null,
			BillStatus: null,
			WorkflowStatus: null,
			Remark: null,
			Approver: null,
			ApprovalTime: null,

			// 基本信息
			Name: null,
			StaffNo: null,
			BirthDate: null,
			Age: null,
			Gender: null,
			Ethnicity: null,
			HighestEducation: null,
			MaritalStatus: null,
			FertilityStatus: null,
			MajorCategory: null,
			MajorName: null,
			PhotoId: null,
			WorkYears: null,
			Order: null,

			// 身份信息
			IdCardNo: null,
			IdCardFrontPhotoId: null,
			IdCardBackPhotoId: null,
			IdCardExpiryDate: null,

			// 户籍信息
			HouseholdRegistration: null,
			NativePlace: null,

			// 政治面貌
			PoliticalStatus: null,
			PartyJoinDate: null,
			PartyBranch: null,
			ArchiveLocation: null,
			ArchiveNo: null,
			ArchiveTransferOutDate: null,
			ArchiveTransferInDate: null,

			// 联系方式
			HomeAddress: null,
			Phone: null,
			Email: null,

			// 银行账户
			SalaryBank: null,
			SalaryAccount: null,
			BonusBank: null,
			BonusAccount: null,

			// 工作信息
			OrgId: null,
			GroupId: null,
			JobPositionId: null,
			ResumeId: null,
			HireDate: null,
			ConfirmationDate: null,
			EmploymentType: null,
			ContractType: null,
			ContractNo: null,
			ContractStartDate: null,
			ContractEndDate: null,
			ResignationDate: null,
			ResignationReason: null,
			ResignationType: null,
			State: '在职',

			// 其他
			BloodType: null,
			Hobbies: null,
			IsVeteran: null,
			VeteranCertificateId: null,
			CompanyYears: null,
			JoinWorkDate: null,
			ArchiveAgeDate: null,

			// 新增字段 - 亲属关系
			HasRelativeInCompany: false, // 默认值为"否"
			RelationshipType: null,
			RelativeName: null,
			IsLaborRelationshipTerminated: false,

			// 新增字段 - 身体信息
			Height: null,
			Weight: null,
		} as any,
		ActionName: null,
		IsMyApprove: false,
		Remark: null,
	},
	AllSysOrgs: [],
	AllSysGroups: [],
});

// 招聘需求池相关的响应式数据
const recruitPublishOptions = ref<any[]>([]);
const recruitPublishLoading = ref(false);
const searchTimer = ref<NodeJS.Timeout | null>(null);

// 计算属性
const hasEntityId = computed(() => {
	const entity = stateData.vmModel.Entity as any;
	return !!(entity && entity.ID);
});

// 公共的响应处理函数
const handleApiResponse = (response: any, isSubmit = false) => {
	// 根据操作类型显示不同的消息
	if (isSubmit) {
		ElMessage.success(ci.proxy?.$t('message._system.common.vm.submittip') || '提交成功');
	} else {
		ElMessage.success(ci.proxy?.$t('message._system.common.vm.savetip') || '保存成功');
	}

	emit('refresh');

	// 统一处理ID设置
	if (response?.Entity?.ID) {
		stateData.vmModel.Entity = response.Entity;
	} else if (response?.ID) {
		stateData.vmModel.Entity.ID = response.ID;
		stateData.vmModel.Entity.OrgId = response.OrgId;
		stateData.vmModel.Entity.GroupId = response.GroupId;
		stateData.vmModel.Entity.JobPositionId = response.JobPositionId;
	}

	// 根据操作类型处理不同逻辑
	if (isSubmit) {
		closeDialog();
	} else {
		hasSavedOnce.value = true;
	}

	loading.value = false; // 重置loading状态

	nextTick(() => {
		setupHeaderButtons();
	});
};

// 统一的错误处理函数
const handleError = (error: any) => {
	other.setFormError(ci, error);
	loading.value = false;
};

// 公共的表单提交函数
const submitForm = (apiCall: () => Promise<any>, beforeSubmit: () => void, isSubmit = false) => {
	other.validateFormWithMessage(formRef.value, () => {
		loading.value = true;
		beforeSubmit();
		apiCall()
			.then((response: any) => handleApiResponse(response, isSubmit))
			.catch(handleError);
	});
};

// 取消
const onClose = () => {
	closeDialog();
};

// 保存
const onSave = () => {
	submitForm(
		() => {
			// 创建一个深拷贝，确保新增时不发送无效的 ID 字段
			const submitData = JSON.parse(JSON.stringify(stateData.vmModel));
			if (!submitData.Entity.ID) {
				// 如果没有有效的 ID，删除该字段
				delete submitData.Entity.ID;
			}
			return api().add(submitData);
		},
		() => {
			stateData.vmModel.Entity.BillStatus = BILL_STATUS.DRAFT;
		},
		false
	);
};

// 提交
const onSubmit = () => {
	submitForm(
		() => api().edit(stateData.vmModel),
		() => {
			stateData.vmModel.Entity.WorkflowStatus = BILL_STATUS.SUBMITTING;
		},
		true
	);
};

const activeTab = ref('main');

// 身份证上传识别处理
const handleUploadRefresh = async (value: string, type: 'front' | 'back') => {
	if (!value) return;
	await recognizeIdCard(value, type, stateData.vmModel.Entity);
};

// 解析身份证号码信息
const parseIdCardInfo = () => {
	if (stateData.vmModel.Entity.IdCardNo) {
		useIdCardParser().parseAndFill(stateData.vmModel.Entity.IdCardNo, stateData.vmModel.Entity);
	}
};

// 初始化页面数据
const initializePageData = () => {
	const wtmdata = ci.attrs['wtmdata'] as any;
	if (wtmdata?.ID) {
		// 如果是编辑模式（有BillCode说明是已保存的单据）
		if (wtmdata.BillCode) {
			stateData.vmModel.Entity.ID = wtmdata.ID;
			stateData.vmModel.Entity = wtmdata;
			hasSavedOnce.value = true;
		} else {
			// 如果只是获取到了当前登录人信息，不算已保存
			stateData.vmModel.Entity = { ...wtmdata };
			hasSavedOnce.value = false;
		}
	}
};

// 加载选择列表数据
const loadSelectListData = async () => {
	const [orgs, billCode] = await Promise.allSettled([commonApi().getOrganizations(), api().getBillCode()]);

	// 处理成功的结果
	if (orgs.status === 'fulfilled') stateData.AllSysOrgs = orgs.value;
	if (billCode.status === 'fulfilled') stateData.vmModel.Entity.BillCode = billCode.value?.Data || null;
};

// 搜索招聘需求池的方法
const searchRecruitPublish = async (query: string) => {
	// 清除之前的定时器
	if (searchTimer.value) {
		clearTimeout(searchTimer.value);
	}

	// 设置防抖延迟
	searchTimer.value = setTimeout(async () => {
		if (query !== '') {
			recruitPublishLoading.value = true;
			try {
				// 直接调用招聘需求池API
				const response = await SysHrRecruitPublishRequestBillApi().search({ IsExternalPublish: true });
				recruitPublishOptions.value = response.Data;
			} catch (error) {
				console.error('通过是否对外发布查询招聘需求池失败:', error);
				recruitPublishOptions.value = [];
			} finally {
				recruitPublishLoading.value = false;
			}
		} else {
			recruitPublishOptions.value = [];
		}
	}, 300); // 300ms 防抖延迟
};

// 计算工龄
watch(
	() => stateData.vmModel.Entity.JoinWorkDate,
	(newJoinWorkDate) => {
		if (newJoinWorkDate) {
			stateData.vmModel.Entity.WorkYears = other.calculateWorkYears(newJoinWorkDate).decimalYears;
		}
	}
);

// 计算司龄
watch(
	() => stateData.vmModel.Entity.HireDate,
	(newHireDate) => {
		if (newHireDate) {
			const companyYearsResult = other.calculateWorkYears(newHireDate);
			stateData.vmModel.Entity.CompanyYears = companyYearsResult.decimalYears;
		} else {
			stateData.vmModel.Entity.CompanyYears = null;
		}
	}
);

// 页面加载时
onMounted(async () => {
	loading.value = true;
	initializePageData();

	try {
		// 并行加载选择列表数据
		await loadSelectListData();
	} catch (error) {
		other.setFormError(ci, error);
	} finally {
		loading.value = false;
		nextTick(() => {
			setupHeaderButtons();
		});
	}
});

// 组件卸载时清理
onUnmounted(() => {
	// 清理搜索定时器
	if (searchTimer.value) {
		clearTimeout(searchTimer.value);
	}
});

// 定义子组件向父组件传值事件
const emit = defineEmits(['refresh', 'closeDialog', 'updateHeaderButtons']);

// 关闭弹窗
const closeDialog = () => {
	emit('closeDialog');
};

// 设置对话框头部按钮
const setupHeaderButtons = () => {
	const headerButtons = [
		{
			text: BUTTON_TEXTS.SAVE,
			type: undefined,
			onClick: onSave,
			visible: !hasSavedOnce.value, // 未保存过时显示保存按钮
		},
		{
			text: BUTTON_TEXTS.SUBMIT,
			confirm: '提交单据以后无法修改，是否确认提交?',
			type: 'primary',
			onClick: onSubmit,
			visible: hasSavedOnce.value && hasEntityId.value, // 已保存过且有实体ID时显示提交按钮
		},
		{
			text: BUTTON_TEXTS.CLOSE,
			type: 'default',
			onClick: onClose,
			visible: true,
		},
	];

	emit('updateHeaderButtons', headerButtons);
};
</script>
